#include <iostream>
#include <algorithm>

using namespace std;

const int N = 5e4 + 10;
typedef long long LL;

int n;
struct node
{
	int w, s;
}a[N];

//i在j前面
bool cmp(node x, node y)
{
	return max(-x.s, x.w - y.s) < max(-y.s, y.w - x.s);
}

int main()
{
	cin >> n;
	for(int i = 1; i <= n; i++) cin >> a[i].w >> a[i].s;

	sort(a + 1, a + 1 + n, cmp);

	LL ret = -1e9 - 10, tmp = 0;
	for(int i = 1; i <= n; i++)
	{
		ret = max(ret, tmp - a[i].s);
		tmp += a[i].w;
	}
	cout << ret << endl;

	return 0;
}


